package com.eascs.spider.hr.common.component;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.UuidUtil;
import com.eascs.notify.constant.ModelResult;
import com.eascs.notify.mail.MailNotifier;
import com.eascs.notify.mail.MailNotifyRequest;
import com.eascs.notify.mail.MailNotifyResponse;
import com.eascs.notify.mail.MailSendType;

@Component
public class MailNotifierComponent {

	private static Logger logger = LoggerFactory.getLogger(MailNotifierComponent.class);

	@Reference
	private MailNotifier mailNotifier;

	public String notify(String recipient, String title, String content, String bizCode) {
		logger.debug("notify recipient:{} title:{} content:{} bizCode:{}", recipient, title, content, bizCode);
		MailNotifyRequest mailNotifyRequest = new MailNotifyRequest();
		mailNotifyRequest.setRequestId(UuidUtil.generateUuid());
		mailNotifyRequest.setRequestDateTime(new Date());
		mailNotifyRequest.setSystemCode("ticket");
		mailNotifyRequest.setBizCode(bizCode);
		mailNotifyRequest.setMailSendType(MailSendType.GENERAL);
		mailNotifyRequest.setRecipientTo(recipient);
		mailNotifyRequest.setTitle(title);
		mailNotifyRequest.setContent(content);
		ModelResult<MailNotifyResponse> response = mailNotifier.notify(mailNotifyRequest);
		return response.getModel().getResponseId();
	}
}
